package com.jiangjiang.eshop.order.status;

import com.jiangjiang.eshop.common.help.DateHelper;
import com.jiangjiang.eshop.order.constant.OrderOperateType;
import com.jiangjiang.eshop.order.domain.OrderOperateLogEntity;
import com.jiangjiang.eshop.order.dto.OrderInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;

/**
 * @ClassName OrderOperateLogFactory
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/24 21:55
 * @Version 1.0
 **/
@Component
public class OrderOperateLogFactory {

    @Autowired
    private DateHelper dateHelper;

    /**
     * 获取订单的操作内容
     * @param order 订单数据
     * @param operateType 操作类型
     * @return
     */
    public OrderOperateLogEntity get(OrderInfoDTO order,Integer operateType) throws Exception{
        String operateContent = null;
        if(OrderOperateType.CREATE_ORDER.equals(operateType)) {
            operateContent = "完成订单创建，订单编号为：" + order.getOrderNo();
        } else if(OrderOperateType.CANCEL_ORDER.equals(operateType)) {
            operateContent = "取消订单，订单编号为：" + order.getOrderNo();
        } else if(OrderOperateType.PAY_ORDER.equals(operateType)) {
            operateContent = "支付订单，订单编号为：" + order.getOrderNo() + "，支付金额为：" + order.getPayableAmount();
        } else if(OrderOperateType.GOODS_DELIVERY.equals(operateType)) {
            operateContent = "已经将订单中的商品进行发货";
        } else if(OrderOperateType.CONFIRM_RECEIPT.equals(operateType)) {
            operateContent = "完成确认收货";
        } else if(OrderOperateType.APPLY_RETURN_GOODS.equals(operateType)) {
            operateContent = "申请退货";
        } else if(OrderOperateType.RETURN_GOODS_REJECTED.equals(operateType)) {
            operateContent = "退货申请审核不通过";
        } else if(OrderOperateType.RETURN_GOODS_APPROVED.equals(operateType)) {
            operateContent = "退货申请审核已通过";
        } else if(OrderOperateType.SEND_OUT_RETURN_GOODS.equals(operateType)) {
            operateContent = "寄送退货商品";
        } else if(OrderOperateType.CONFIRM_RETURN_GOODS_RECEIPT.equals(operateType)) {
            operateContent = "确认收到退货商品";
        } else if(OrderOperateType.FINISHED_RETURN_GOODS_INPUT.equals(operateType)) {
            operateContent = "完成退货商品入库";
        } else if(OrderOperateType.FINISHED_RETURN_GOODS_REFUND.equals(operateType)) {
            operateContent = "完成退款";
        }

       return createLogEntity(order, operateType, operateContent);


    }

    /**
     * 创建订单操作日志
     * @param order 订单数据
     * @param operateType 操作类型
     * @param operateContent 操作内容
     * @return
     */
    private OrderOperateLogEntity createLogEntity(OrderInfoDTO order, Integer operateType, String operateContent) throws Exception {

        return OrderOperateLogEntity.builder()
                .orderInfoId(order.getId())
                .operateType(operateType)
                .operateContent(operateContent)
                .gmtCreate(dateHelper.getCurrentDate())
                .gmtModified(dateHelper.getCurrentDate())
                .build();
    }
}
